package com.zhf.dao;

import com.zhf.bean.Administrator;
import com.zhf.utils.DruidUtils;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/10/16 23:23
 */
public class AdministratorDaoImp implements AdministratorDao {
    @Override
    public Administrator Login(Administrator administrator) {
        String userName=administrator.getUserName();
        String password=administrator.getPassword();
        Object[] params={userName,password};
        try {
            //获取QueryRunner对象
            QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
            //编写SQL
            String sql="select * from t_admin where userName = ? and password = ?";
            //执行SQL
            Administrator query = queryRunner.query(sql, new BeanHandler<Administrator>(Administrator.class),params);
            return query;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
